<template>
  <a-modal
    title="下载附件"
    :width="810"
    :visible="visible"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <template slot="footer">
      <a-button @click="handleCancel">关闭</a-button>
    </template>
    <a-card>
      <a-list item-layout="horizontal" :data-source="fileList">
        <a-list-item slot="renderItem" slot-scope="item">
          <a-list-item-meta>
            <a slot="title" :href="item.url" target="_blank">{{ item.name }}</a>
          </a-list-item-meta>
        </a-list-item>
      </a-list>
    </a-card>
  </a-modal>
</template>

<script>

import { queryCPFile } from '@/api/vote/candidate'

export default {
  name: 'DownloadFiles',
  // props: {
  //   fileAddr: {
  //     type: String,
  //     default: 'D:/file/小a1-1-11/1/1_理工职称评审系统2020年12月10日.pdf,' +
  //       'D:/file/小a1-1-11/1/1_理工职称评审系统2020年12月10日.docx'
  //   }
  // },
  data() {
    return {
      cp: {},
      fileList: [],
      uploading: false,
      visible: false
    }
  },
  created() {
  },
  methods: {
    downLoad (record) {
      this.visible = true
      this.cp = record
      this.loading = true
      this.fileList = []
      const that = this
      this.loading = true
      queryCPFile(this.cp).then(res => {
        console.log(res)
        if (res.result !== null && res.result.length > 0) {
          const files = res.result.toString().split(',')
          for (let i = 0; i < files.length; i++) {
            const file = files[i]
            that.fileList.push({
              uid: i + 1,
              status: 'done',
              name: file.substr(file.lastIndexOf('/') + 1),
              url: file
            })
          }
        }
        that.loading = false
      }).catch(err => {
        that.loading = false
        that.$message.error(err.result)
        that.visible = false
      })
    },
    // handleOK() {
    //   this.$emit('ok')
    // },
    handleCancel () {
      this.visible = false
    }
  },
}
</script>

<style scoped>

</style>
